#include <stdio.h>
#include "ofc/DXML.h"
#include "ofc/DText.h"

int main(int argc, char *argv[])
{
#ifdef HAVE_DXML 
  DXMLWriter *wrtr = [DXMLWriter new];
  DText      *dest = [DText      new];  // Use a text string as destination

  if ([wrtr start :dest :'|'])
  {
    if (![wrtr startDocument :"1.0" :NULL :YES])      // Write start of document
      printf("Could not write start of xml document.\n");

    if (![wrtr comment :"Example of the XMLWriter"])  // Write comment
      printf("Could not write xml comment.\n");

    if (![wrtr startElement :"ELEMENT1"])             // Write start of element
      printf("Could not write start element.\n");

    if (![wrtr attribute :"attribute1" :"value1"])    // Write attribute for element
      printf("Could not write attribute.\n");

    if (![wrtr characters :"Some text & another text."])  // Write norml text
      printf("Could not write normal text.\n");
    
    if (![wrtr endElement])                           // Write end of element
      printf("Could not write end of element.\n");
    
    if (![wrtr endDocument])                          // Write end of document
      printf("Could not write end of xml document.\n");
   
    printf("Result xml document:\n%s\n", [dest cstring]);  // Print result
  }
  else
    printf("Could not start writing xml document.\n");

  [wrtr free];                         // Cleanup
  [dest free];
#else
  printf("DXML is not present in the library.\n");
#endif
  return 0;
}

